/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved. 
 */
package com.icinfo.cloud.provider.punish.actscode.controller;

import com.icinfo.cloud.provider.punish.actscode.dto.ActsCodeDto;
import com.icinfo.cloud.provider.punish.actscode.dto.ActsCodeDtoBatch;
import com.icinfo.cloud.provider.punish.actscode.dto.ActsCodeRevokeDto;
import com.icinfo.cloud.provider.punish.actscode.service.ICaseActsCodeInfoService;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 描述:  case_acts_code_info 对应的Controller类.<br>
 *
 * @author framework generator
 * @date 2022年11月08日
 */
@RestController
@RequestMapping("/punish/caseActsCodeInfo")
public class CaseActsCodeInfoController extends BaseController {
    /**
     * 日志记录器
     */
    private static final Logger logger = LoggerFactory.getLogger(CaseActsCodeInfoController.class);

    @Autowired
    private ICaseActsCodeInfoService caseActsCodeInfoService;
    /**
     * 保存行政行为码信息
     * @author liyafeng
     * @date 2022/11/8
      * @param actsCodeDto
     * @return {@link Result< String>}
     */
    @PostMapping("/saveCaseActsCodeInfo")
    public Result<String> saveCaseActsCodeInfo(@Validated @RequestBody ActsCodeDto actsCodeDto){
        int num=caseActsCodeInfoService.saveCaseActsCodeInfo(actsCodeDto);
        if(num>0){
            return Result.success("success","保存成功");
        }
        return Result.error("保存失败");

    }
    @PostMapping("/saveCaseActsCodeInfoBatch")
    public Result<String> saveCaseActsCodeInfoBatch(@Validated @RequestBody ActsCodeDtoBatch actsCodeDtoBatch){
        int num=0;
        for (String caseId:actsCodeDtoBatch.getCaseIds()) {
            ActsCodeDto actsCodeDto=new ActsCodeDto();
            actsCodeDto.setCaseId(caseId);
            num=caseActsCodeInfoService.saveCaseActsCodeInfo(actsCodeDto);
        }
        if(num>0){
            return Result.success("success","保存成功");
        }
        return Result.error("保存失败");

    }
    /**
     * 行政行为码注销
     * @author liyafeng
     * @date 2023/1/13
      * @param actsCodeRevokeDto
     * @return {@link Result< String>}
     */
    @PostMapping("/revoke")
    public Result<String> revoke(@Validated @RequestBody ActsCodeRevokeDto actsCodeRevokeDto){
        int num=caseActsCodeInfoService.revoke(actsCodeRevokeDto);
        if(num>0){
            return Result.success("success","保存成功");
        }
        return Result.error("保存失败");

    }
}